package com.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.entity.MachineEntity;
import com.service.MachineService;
import com.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author Losca
 * @date 2022/4/29 19:16
 */
@RestController
@RequestMapping("/machine")
public class MachineController {
    @Autowired
    MachineService machineService;

    @GetMapping("/allMachine")
    public R allMachine(@RequestParam(defaultValue = "1") Integer pageNum
            , @RequestParam(defaultValue = "10") Integer pageSize
            , @RequestParam(defaultValue = "") String value) {
        Page<MachineEntity> machineEntityPage = machineService.allMachine(pageNum, pageSize, value);
        return R.ok().put("data", machineEntityPage);
    }

    @PostMapping("/updateMachine")
    public R updateMachine(MachineEntity machine){
        machineService.updateById(machine);
        return R.ok();
    }

    @PostMapping("/addMachine")
    public R addMachine(@RequestBody MachineEntity machine){
        machineService.insert(machine);
        return R.ok();
    }

    @GetMapping("/list")
    public R list(){
        return R.ok().put("data", machineService.selectList(null));
    }


}
